package com.lc.cehui.ui.activity;

import android.os.Bundle;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.LogUtils;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppActivity;
import com.lc.cehui.base.BaseDialog;
import com.lc.cehui.dialog.MessageDialog;
import com.lc.cehui.http.request.LoginOutApi;
import com.lc.cehui.http.response.LoginBean;
import com.lc.cehui.manager.ActivityManager;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.ui.activity.land.EditPassWordActivity;
import com.lc.cehui.ui.activity.land.LoginActivity;
import com.lc.cehui.ui.activity.mine.FeedbackActivity;
import com.lc.cehui.util.CourseUtils;
import com.lc.cehui.util.SPUtil;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends AppActivity {
    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.sb_setting_password, R.id.sb_setting_feed, R.id.sb_setting_us,R.id.sb_setting_out})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sb_setting_password:
                startActivity(EditPassWordActivity.class);
                break;
            case R.id.sb_setting_feed:
                startActivity(FeedbackActivity.class);
                break;
            case R.id.sb_setting_us:
                break;
            case R.id.sb_setting_out:
                new MessageDialog.Builder(getActivity())
                        // 标题可以不用填写
                        .setTitle("退出登录")
                        // 内容必须要填写
                        .setMessage("您是否要退出登录？")
                        // 确定按钮文本
                        .setConfirm(getString(R.string.common_confirm))
                        // 设置 null 表示不显示取消按钮
                        .setCancel(getString(R.string.common_cancel))
                        // 设置点击按钮后不关闭对话框
                        //.setAutoDismiss(false)
                        .setListener(new MessageDialog.OnListener() {

                            @Override
                            public void onConfirm(BaseDialog dialog) {
                                // 进行内存优化，销毁除登录页之外的所有界面
                                ActivityManager.getInstance().finishAllActivities(MainActivity.class);
                                startActivity(LoginActivity.class);
                                SPUtil.put(SettingActivity.this, IntentKey.RID, 0);
                                EasyHttp.post(SettingActivity.this)
                                        .api(new LoginOutApi().setUserid(SPUtil.get(SettingActivity.this,IntentKey.USERID,0)+"")
                                                .setToken(SPUtil.get(SettingActivity.this,IntentKey.TOKEN,""))
                                                .setType(SPUtil.get(SettingActivity.this,IntentKey.TYPE,0)+""))
                                        .request(new HttpCallback<LoginBean>(SettingActivity.this) {
                                            @Override
                                            public void onSucceed(LoginBean data) {
                                                LogUtils.e(JSON.toJSONString(data));
                                                if (callBackCode(data)){
                                                }
                                            }
                                        });

                            }

                            @Override
                            public void onCancel(BaseDialog dialog) {
                                dialog.dismiss();
                            }
                        })
                        .show();
                break;

        }
    }
}
